<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>器械领用</title>
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/css/themes/icon.css"/>">
<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
</head>

<body>
<script type="text/javascript">
$(function(){
	//自动赋值
	$('#QXFCP').combogrid({
		onChange: function (newValue, oldValue) {
			var qcName=$('#QXFCP').combogrid('getText');
			$.getJSON("selectHisInstrumentroomByName", {"qcName": qcName}, function(data){
				$('#qxfjcsl').numberbox('setValue',data.qcNumber);
				$('#qxlysl').numberspinner({max:data.qcNumber});
			});
			$.getJSON("selectHisPurchaseByName", {"cpName": qcName}, function(data){
				$('#cpph').textbox('setValue',data.cgBatchnumber);
			});
		}
	});
	
	//数字微调
	$('#qxlysl').numberspinner({
		onChange: function (newValue, oldValue) {
			var qxfjcsl=$('#qxfjcsl').numberbox('getValue');
			if(qxfjcsl==''){
				$.messager.alert('温馨提示', '请先选择您需要领用的产品名称!','info');
				$('#qxlysl').numberspinner('setValue',0);
				$('#qxfjcsl').numberbox('setValue','');
			}else{
				var jcsl=$('#qxfjcsl').numberbox('getValue');
				var o=parseInt(jcsl)+parseInt(oldValue)-parseInt(newValue);
				$('#qxfjcsl').numberbox('setValue',o);
			}
		}
	});
	
	//加入到临时表
	$('#add-lslyTable').linkbutton({
		onClick : function() {
			var QXFCPid=$('#QXFCP').combogrid('getValue');
			var QXFCPname=$('#QXFCP').combogrid('getText');
			var cpph=$('#cpph').textbox('getText');
			var qxfjcsl=$('#qxfjcsl').numberbox('getValue');
			var qxlysl=$('#qxlysl').numberspinner('getValue');
			var qxlybz=$('#qxlybz').textbox('getValue');
			var qxlyObject=$('#qxlyObject').combogrid('getValue');
			var qxlyck=$('#qxlyck').combogrid('getValue');
			var qxlyDate=$('#qxlyDate').datebox('getText');
			$.getJSON("selectHisPurchaseByName", {"cpName": QXFCPname}, function(data){
				var unit=data.cgUnit;
				
				var rows=$('#thpqxUse').datagrid('getRows');
				var ii=0;
				for(var i=0;i<rows.length;i++){
					var name=rows[i].cpName;
					if(name==QXFCPname){
						ii++;
					}
				}
				if(QXFCPname=='' || qxlyDate=='' || qxlyck=='' || qxlyObject=='' || parseInt(qxlysl)<1 ){
					$.messager.alert("温馨提示", "请把数据填充完整!",'info');
				}else if(ii>0){
					$.messager.alert("提示", "产品已存在临时领用中，请勿重复添加!");
					$('#qxlyInfo').form("clear");
				}else{
					$('#thpqxUse').datagrid('appendRow', {
						'hisDetailsofequipments.cpNo' : QXFCPid,
						'cpName' : QXFCPname,
						'hisDetailsofequipments.ckBalance' : qxfjcsl,
						'cgUnit' : unit,
						'cgBatchnumber' : cpph,
						'hisDetailsofequipments.qclyxqNumber' : qxlysl,
						'hisDetailsofequipments.qclyxqRemarks' : qxlybz
					});
					$('#qxlyInfo').form("clear");
				}
			});
		}
	});
	
	//领用
	$('#submit-qxuse').linkbutton({
		onClick : function() {
			//将datagrid中的数据行保存到隐式表单域中
			//1、获取新增的数据行
			var rows = $('#thpqxUse').datagrid('getChanges');
			//为每一行生成对应的隐藏表单域
			var today='${DetailsofequipmentId }'*1;
			var ff_QiXieUse=$('#ff_QiXieUse');
			var qxlyObject=$('#qxlyObject').combogrid('getValue');
			var qxlyck=$('#qxlyck').combogrid('getValue');
			var qxlyDate=$('#qxlyDate').datebox('getText');
			var qxlyState='已确认';
			for(var i = 0; i < rows.length; i ++){
				$("<input type='hidden' x='y'>").attr("name",
						"hisDetailsofequipments[" + i + '].qclyxqNo').val(
								today+i).appendTo(ff_QiXieUse);
				$("<input type='hidden' x='y'>").attr("name",
						"hisDetailsofequipments[" + i + '].ckNo').val(
								qxlyck).appendTo(ff_QiXieUse);
				$("<input type='hidden' x='y'>").attr("name",
						"hisDetailsofequipments[" + i + '].qclyxqDate').val(
								qxlyDate).appendTo(ff_QiXieUse);
				$("<input type='hidden' x='y'>").attr("name",
						"hisDetailsofequipments[" + i + '].qclyxqState').val(
								qxlyState).appendTo(ff_QiXieUse);
				$("<input type='hidden' x='y'>").attr("name",
						"hisDetailsofequipments[" + i + '].qxlyxqObject').val(
								qxlyObject).appendTo(ff_QiXieUse);
				generateHidden(rows[i], "cpNo", i);
				generateHidden(rows[i], "ckBalance", i);
				generateHidden(rows[i], "qclyxqNumber", i);
				generateHidden(rows[i], "qclyxqRemarks", i);
			}
			//提交表单
			if(rows.length != 0){
				$('#ff_QiXieUse').form('submit', {
					success: function(v){
						var json = eval("(" + v + ")");
						//alert(json);
						if(json=='操作成功'){
							$(":hidden[x='y']").remove();
							$('#thpqxUse').datagrid('loadData', { total: 0, rows: [] });
							$.messager.alert('温馨提示', "领用"+json);
							$('#ff_QiXieUse').form("clear");
							$("#win-QiXieUse").window("close");
						}else{
							$.messager.alert('温馨提示', json,'info');
						}
					}
				});
			}
		}
	});
	
	function generateHidden(row, name, i) {
		var ff_QiXieUse = $("#ff_QiXieUse");
		$("<input type='hidden' x='y'>").attr("name",
				"hisDetailsofequipments[" + i + '].'  + name).val(
				row['hisDetailsofequipments.'+name]).appendTo(ff_QiXieUse);
	}
})
</script>
<style type="text/css">
	*{
		font-size:12px;
	}
	#QiXieUseContent{
		padding-bottom: 10px;
	}
	#QiXieUseInfo{
		width:100%;
		overflow: hidden;
	}
	li{
		float: left;
		list-style: none;
	}
</style>

	<!-- 器械领用 -->
	<!-- <div id="win-QiXieUse" class="easyui-window" title="器械领用" data-options="collapsible:false,
		minimizable:false,
		maximizable:false,
		modal:true,
		iconCls:'icon-recipients'"
		style="width: 806px; height: 500px;"> -->
		<form id="ff_QiXieUse" action="addQiXieDetailsofequipment" method="post">
			<div id="QiXieUseContent">
				<div id="QiXieUseInfo" style="background-color: rgb(236,243,255)">
					<ul>
						<li style="margin:0px 30px 5px 0px;">领用单编号&nbsp;<input value="${DetailsofequipmentId }" class="easyui-textbox" data-options="width: 150" readonly="readonly"></li>
						<li style="margin:0px 0px 5px 0px;">状态&nbsp;<select id="qxlyState" class="easyui-combobox" data-options="width: 80" readonly="readonly">
							<option value="未确认" selected="selected">未确认</option><option value="已确认">已确认</option></select></li>
						<li style="margin:0px 30px 5px 30px;">仓库&nbsp;<input id="qxlyck" class="easyui-combogrid" data-options="width: 100,
							url:'selectAllHisWarehouse',
							idField:'ckNo',
							panelHeight:'auto',
							textField:'ckName',
							columns:[[
					            {field:'ckName',title:'仓库名称',width:'96px'}
							]]"></li>
						<li style="margin:0px 0px 5px 0px;">领用日期&nbsp;<select id="qxlyDate" class="easyui-datebox" data-options="width: 150"></select></li>
						<li style="margin:0px 0px 15px 12px;">领用对象&nbsp;<input id="qxlyObject" class="easyui-combogrid" data-options="width: 150,
							url:'selectAllHisDepartment',
							idField:'ksNo',
							panelHeight:'auto',
							textField:'ksName',
							columns:[[
					            {field:'ksName',title:'科室名称',width:146}
							]]"></li>
					</ul>
				</div>
				<div style="border-top:1px solid #95B8e7;width:100%;height:342px;overflow: hidden;">
			        <div>
			        	<div id="qxlyInfo" style="overflow: hidden;">
			        		<ul>
								<li style="margin:10px 35px 10px 0px;">器械&nbsp;<select id="QXFCP" class="easyui-combogrid" data-options="width: 188,
									url:'selectAllHisInstrumentroom',
									idField:'qcNo',
									panelHeight:'200',
									textField:'qcName',
									columns:[[{field:'qcName',title:'房器械名称',width:'180px'}
									]]"></select></li>
								<li style="margin:10px 37px 10px 0px;">批号&nbsp;<input id="cpph" class="easyui-textbox" data-options="width: 100" readonly="readonly"></li>
								<li style="margin:10px 35px 10px 0px;">结存数量&nbsp;<input id="qxfjcsl" class="easyui-numberbox" data-options="width: 100" readonly="readonly"></li>
								<li style="margin:10px 0px 10px 0px;">领用数量&nbsp;<input id="qxlysl" class="easyui-numberspinner" value="0" data-options="width: 80,min:0,editable:true"></li>
								<li style="margin:0px 0px 10px 0px;">备注&nbsp;<input id="qxlybz" class="easyui-textbox" data-options="width: 540"></li>
								<li style="margin:0px 2px 10px 85px;"><a id="add-lslyTable" class="easyui-linkbutton" style="width:80px;">加入</a></li>
							</ul>
			        	</div>
			        	<div style="border:0px red solid;height:250px;">
							<table id="thpqxUse" class="easyui-datagrid"
								data-options="
									fitColumns:true,
									fit:true,
									singleSelect: true,
									rownumbers: true,
									pagination: true,
									pageSize: 5,
									toolbar: '#qxusetb',
									pageList: [5,10,15,20],
									border:false
									">
								<thead>
									<tr>
										<th data-options="field:'hisDetailsofequipments.cpNo',width:'15%'">器械编号</th>
										<th data-options="field:'cpName',width:'15%'">器械名称</th>
										<th data-options="field:'hisDetailsofequipments.ckBalance',width:'10%'">结存数量</th>
										<th data-options="field:'cgUnit',width:'10%'">单位</th>
										<th data-options="field:'cgBatchnumber',width:'15%'">批号</th>
										<th data-options="field:'hisDetailsofequipments.qclyxqNumber',width:'10%'">领用数量</th>
										<th data-options="field:'hisDetailsofequipments.qclyxqRemarks',width:'25%'">备注</th>
									</tr>
								</thead>
							</table>
							<div id="qxusetb" style="height: auto;padding-left: 30px;">
								<a href="javascript:void(0)" class="easyui-linkbutton"
								data-options="iconCls:'icon-add',plain:true">添加一行</a>
								<a href="javascript:void(0)" class="easyui-linkbutton"
									data-options="iconCls:'icon-remove',plain:true"
									onclick="removeit()">移除一行</a> <a href="javascript:void(0)"
									class="easyui-linkbutton"
									data-options="iconCls:'icon-ok',plain:true">应用</a>
								<a href="javascript:void(0)" class="easyui-linkbutton"
									data-options="iconCls:'icon-undo',plain:true" onclick="reject()">撤销</a>
							</div>
			        	</div>
			        </div>
			    </div>
			    <div style="margin:5px 5px 0px 0px;text-align: right;">
					<a id="submit-qxuse" class="easyui-linkbutton" data-options="iconCls:'icon-ok'">领用</a>
					<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel'" href="javascript:$('#win-QiXieUse').window('close');" onclick="">取消</a>
				</div>
			</div>
		</form>
	<!-- </div> -->
</body>
</html>